//
//  LBZaiLineCell.m
//  V-Learn
//
//  Created by Apple on 2019/1/1.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBZaiLineCell.h"
#define kLeftMargin 15
#define kRowHeight 44
@interface LBZaiLineCell ()
@property (nonatomic, strong) UILabel *needLabel;
@property (nonatomic, strong) UIImageView *nextImageView;
@property (nonatomic, strong) UIView *bgView;
@end
@implementation LBZaiLineCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.bgView];
        self.contentView.backgroundColor = rgb(242,242,242);
            self.bgView.layer.cornerRadius = 4;
            self.bgView.layer.masksToBounds = YES;
            self.bgView.backgroundColor = [UIColor whiteColor];
        
            [self.bgView makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(15);
                make.right.mas_equalTo(-15);
                make.bottom.top.mas_equalTo(0);
            }];
        [self.bgView addSubview:self.needLabel];
        [self.bgView addSubview:self.titleLabel];
        [self.bgView addSubview:self.textField];
        [self.bgView addSubview:self.nextImageView];
    }
    return self;
}
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.userInteractionEnabled = YES;
    }
    return _bgView;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    // 调整cell分割线的边距：top, left, bottom, right
    
    self.separatorInset = UIEdgeInsetsMake(0, kLeftMargin, 0, kLeftMargin);
//    self.needLabel.frame = CGRectMake(kLeftMargin - 16, 0, 16, kRowHeight);
    self.titleLabel.frame = CGRectMake(kLeftMargin, 0, 150*ScaleX, kRowHeight);
//    self.nextImageView.frame = CGRectMake(SCREEN_WIDTH - kLeftMargin - 8, (kRowHeight - 13) / 2, 8, 13);
//    self.textField.frame = CGRectMake(self.nextImageView.frame.origin.x - 200, 0, 200, kRowHeight);
    [self.nextImageView makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(8*kScaleFit, 13*kScaleFit));
        make.centerY.mas_equalTo(self.bgView);
    }];
    [self.textField makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.nextImageView.mas_left).mas_equalTo(-5*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(200, 44));
        make.top.bottom.mas_equalTo(0);
    }];

    if (self.isNext) {
        self.nextImageView.hidden = NO;
    } else {
        self.nextImageView.hidden = YES;
    }
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.backgroundColor = [UIColor clearColor];
        _titleLabel.textColor = BR_RGB_HEX(0x464646, 1.0);
        _titleLabel.font = [UIFont systemFontOfSize:15.0f * ScaleX];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _titleLabel;
}


- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc]init];
        _textField.backgroundColor = [UIColor clearColor];
        _textField.font = [UIFont systemFontOfSize:16.0f * kScaleFit];
        _textField.textAlignment = NSTextAlignmentRight;
        _textField.textColor = BR_RGB_HEX(0x666666, 1.0);
    }
    return _textField;
}

- (UIImageView *)nextImageView {
    if (!_nextImageView) {
        _nextImageView = [[UIImageView alloc]init];
        _nextImageView.backgroundColor = [UIColor clearColor];
        _nextImageView.image = [UIImage imageNamed:@"home_right_arrow"];
    }
    return _nextImageView;
}

@end
